package 小米笔试题;
/*
 public static void sort(int a[],int m,int b[],int n){
        int p1=0,p2=0;
        int sorted[]=new int[m+n];
        int cur;
        while(p1<m||p2<n){
            if(p1==m){
                cur=b[p2++];
            }
            else if(p2==n){
                cur=a[p1++];
            }
            else if(a[p1]<b[p2]){
                cur=a[p1++];
            }
            else{
                cur=b[p2++];
            }
            sorted[p1+p2-1]=cur;
        }
        int c[]=new int[m+n];
        for(int i=0;i!=m+n;++i){
            a[i]=sorted[i];
            System.out.print(a[i]+" ");

        }
        //Arrays.toString(c);
       // return a;

    }
 */
//9.1笔试题
import java.util.*;
//合并有序数组
public class Main {
    public static int[] merge(int[] nums1, int m, int[] nums2, int n) {
        int[] arr = new int[m + n];
        int i = 0;
        int p1 = 0;
        int p2 = 0;
        while (p1 < m && p2 < n) {//双指针
            arr[i++] = nums1[p1] <= nums2[p2] ? nums1[p1++] : nums2[p2++];
        }
        while (p1 < m) {
            arr[i++] = nums1[p1++];
        }
        while (p2 < n) {
            arr[i++] = nums2[p2++];
        }
        for (int j = 0; j < m + n; j++)
            nums1[j] = arr[j];
        return arr;
    }
    public static void main(String args[]){
        Scanner scanner=new Scanner(System.in);
        String input=scanner.nextLine();
        String input1[]=input.split(",");

        int m=input1[0].charAt(input1[0].length()-1)-'0';
        int n=input1[1].charAt(input1[0].length()-1)-'0';
        int A[]=new int[m+n];
        int B[]=new int[n];
        String c;
        String cc[];
        c=scanner.next();
        cc=c.split(",");
        for(int i=0;i<cc.length;i++){
            A[i]=Integer.valueOf(cc[i]);// Integer.parseInt
        }
        String a;
        String aa[];
        a=scanner.next();
        aa=a.split(",");
        for(int i=0;i<aa.length;i++){
            B[i]=Integer.valueOf(aa[i]);
        }
        int arr1[]=merge(A,m,B,n);
        for (int i = 0; i < arr1.length; i++) {
            System.out.printf("%d ",arr1[i]);
        }
        int A1[]={1,3,0,0};
        int B1[]={2,4};
        int m1=2,n1=2;
        int arr[]= merge(A1,m1,B1,n1);
    }
}
/*



        String str = scanner.nextLine();
        String[] split = str.split(",");
        int m = split[0].charAt(2) - '0';
        int n = split[1].charAt(2) - '0';
        int[] A = new int[m+n];
        int[] B = new int[n];
        String str1 = scanner.nextLine();
        String[] split1 = str1.split(",");
        for(int i = 0; i < m; i++){
            A[i] = Integer.parseInt(split1[i]);
        }
        String str2 = scanner.nextLine();
        String[] split2 = str2.split(",");
        for(int i = 0; i < n; i++){
            B[i] = Integer.parseInt(split2[i]);
        }
 */